<?
//http://sommeruni.mi.fu-berlin.de/admin/?id=csv&action=teilnehmer&pid=170
if(!isset($_GET['action'],$_GET['pid'])) return;
$action = $_GET['action'];
$pid = $_GET['pid'];

 header("Expires: 0");
 header("Cache-control: private");
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Description: File Transfer");
 header("Content-Type: application/vnd.ms-excel");
 header("Content-disposition: attachment; filename=$action$pid.csv");

$query = "SELECT 2011_hoert.sch_id as 'Benutzer ID' ,2011_schueler.name as 'Name',2011_schueler.vname as 'Vorname', 2011_hoert.paid as 'Bezahlt' FROM `2011_hoert`, 2011_schueler WHERE 2011_hoert.sch_id = 2011_schueler.id AND 2011_hoert.ver_id = '".$pid."' ORDER BY 2011_schueler.name";		
$result = doQuery($query);
$array = mysql_fetch_row($result);
if($array == false){
		return;
	}
	for($i = 0; $i < count($array);$i++){
	
			echo mysql_field_name($result,$i);
	
			if($i < count($array)-1) echo ",";
	}
	echo "\n";
	//print csv names
	while($array !== false){
		for($i = 0; $i < count($array);$i++){
		
			echo "\"".$array[$i]."\"";
			
			if($i < count($array)-1) echo ",";
		}
		echo "\n";		
		$array = mysql_fetch_row($result);
	}	
 
 
exit();
?>